from typing import Optional
from fastapi import APIRouter, Request, Cookie, Depends
from fastapi.responses import HTMLResponse, RedirectResponse
from utils import validate_session
from templates import templates

router = APIRouter()

@router.get("/data-analysis", response_class=HTMLResponse)
async def data_analysis_page(
    request: Request,
    session_id: Optional[str] = Cookie(None),
    username: Optional[str] = Cookie(None)
):
    if not session_id or not username or not validate_session(session_id, username):
        return RedirectResponse(url="/")
    return templates.TemplateResponse("data_analysis.html", {
        "request": request,
        "username": username
    })